package com.haoniu.web.controller.module;

import com.haoniu.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.RedWelfareBagUser;
import com.haoniu.module.service.RedWelfareBagUserService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.List;
/**
 * 福利包的接收用户 信息操作处理
 *
 * @author houyijun
 * @date 2019-04-21
 */
@Controller
@RequestMapping("/module/redWelfareBagUser")
public class RedWelfareBagUserController extends BaseController
{
    private String prefix = "module/redWelfareBagUser";

	@Autowired
	private RedWelfareBagUserService redWelfareBagUserService;

	@RequiresPermissions("module:redWelfareBagUser:view")
	@GetMapping()
	public String redWelfareBagUser()
	{
	    return prefix + "/redWelfareBagUser";
	}

	/**
	 * 查询福利包的接收用户列表
	 */
	@RequiresPermissions("module:redWelfareBagUser:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(RedWelfareBagUser redWelfareBagUser) {
		startPage();
        List<RedWelfareBagUser> list = redWelfareBagUserService.selectRedWelfareBagUserList(redWelfareBagUser);
		return getDataTable(list);
	}

	/**
	 * 新增福利包的接收用户
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存福利包的接收用户
	 */
	@RequiresPermissions("module:redWelfareBagUser:add")
	@Log(title = "福利包的接收用户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(RedWelfareBagUser redWelfareBagUser) {
        redWelfareBagUser.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(redWelfareBagUserService.insertRedWelfareBagUser(redWelfareBagUser));
	}

	/**
	 * 修改福利包的接收用户
	 */
	@GetMapping("/edit/{bagUserId}")
	public String edit(@PathVariable("bagUserId") Integer bagUserId, ModelMap mmap) {
		RedWelfareBagUser redWelfareBagUser = redWelfareBagUserService.selectRedWelfareBagUserById(bagUserId);
		mmap.put("redWelfareBagUser", redWelfareBagUser);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存福利包的接收用户
	 */
	@RequiresPermissions("module:redWelfareBagUser:edit")
	@Log(title = "福利包的接收用户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(RedWelfareBagUser redWelfareBagUser) {
        redWelfareBagUser.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(redWelfareBagUserService.updateRedWelfareBagUser(redWelfareBagUser));
	}

	/**
	 * 删除福利包的接收用户
	 */
	@RequiresPermissions("module:redWelfareBagUser:remove")
	@Log(title = "福利包的接收用户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(redWelfareBagUserService.deleteRedWelfareBagUserByIds(ids));
	}

}
